package com.shph.validation.adapter.impl;

import com.shph.validation.Validator.Strategy;
import com.shph.validation.adapter.RuleParse;
import com.shph.validation.rule.IRule;
import lombok.extern.slf4j.Slf4j;

import static com.shph.validation.Validator.Strategy.*;

@Slf4j
public class EnumRuleParse implements RuleParse<Strategy> {
    @Override
    public IRule parse(Strategy ruleType) {
        try {
            Class<? extends IRule> ruleClass;
            switch (ruleType) {
                case NULL:
                    ruleClass = NULL.getRuleClass();
                    return ruleClass.newInstance();
                case NOT_NULL:
                    ruleClass = NOT_NULL.getRuleClass();
                    return ruleClass.newInstance();
                case ASSERT_TRUE:
                    ruleClass = ASSERT_TRUE.getRuleClass();
                    return ruleClass.newInstance();
                case ASSERT_FALSE:
                    ruleClass = ASSERT_FALSE.getRuleClass();
                    return ruleClass.newInstance();
                case MIN:
                    ruleClass = MIN.getRuleClass();
                    return ruleClass.newInstance();
                case MAX:
                    ruleClass = MAX.getRuleClass();
                    return ruleClass.newInstance();
                case PAST:
                    ruleClass = PAST.getRuleClass();
                    return ruleClass.newInstance();
                case FUTURE:
                    ruleClass = FUTURE.getRuleClass();
                    return ruleClass.newInstance();
                case PATTERN:
                    ruleClass = PATTERN.getRuleClass();
                    return ruleClass.newInstance();
                case EMAIL:
                    ruleClass = EMAIL.getRuleClass();
                    return ruleClass.newInstance();
                case NOT_EMPTY:
                    ruleClass = NOT_EMPTY.getRuleClass();
                    return ruleClass.newInstance();
                default:
                    return null;
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            return null;
        }
    }
}
